﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.Text;
using System.Threading.Tasks;
using UCL.Powersource.ServiceReference.RemoteBuildBridge;

namespace UCL.Powersource.TFS
{
    static class RemoteBuildBridgeHelper
    {
        internal static ServiceReference.RemoteBuildBridge.RemoteBuildBridgeClient CreateConnectionToBuildBridgeService(string webServiceUrl)
        {
            BasicHttpBinding binding = new BasicHttpBinding();
            // I think most (or all) of these are defaults--I just copied them from app.config: 
            binding.SendTimeout = TimeSpan.FromMinutes(5);
            binding.OpenTimeout = TimeSpan.FromMinutes(5);
            binding.CloseTimeout = TimeSpan.FromMinutes(5);
            binding.ReceiveTimeout = TimeSpan.FromMinutes(20);
            binding.AllowCookies = false;
            binding.BypassProxyOnLocal = false;
            binding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
            binding.MessageEncoding = WSMessageEncoding.Text;
            binding.TextEncoding = System.Text.Encoding.UTF8;
            binding.TransferMode = TransferMode.Buffered;
            binding.UseDefaultWebProxy = true;
            binding.MaxReceivedMessageSize = 128 * 1024 * 1024;
            binding.MaxBufferPoolSize = 64 * 1024 * 1024;
            binding.MaxBufferSize = (int)binding.MaxReceivedMessageSize;
            EndpointAddress ea = new EndpointAddress(webServiceUrl);
            var ibb = new RemoteBuildBridgeClient(binding, ea);  //"BasicHttpBinding_IRemoteBuildBridge"
            return ibb;
        }
    }
}
